import 'dart:async';

// import 'package:enjoy_plus_flutter_7/utils/Request_Dio.dart';
import 'package:flutter/material.dart';

import '../../api/home.dart';
import 'home_nav.dart';
import 'home_notfiy_list.dart';

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  int _count = 0;
  Timer? _timer;
  List _notifyList = [];
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getData();
  }

  getData() async {
    final res = await getNotfiyApi();
    // PromptAction.success(res);
    // final res = await requestDio.get('/announcement');
    // print(res);
    setState(() {
      _notifyList = res;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: const Color.fromARGB(40, 85, 145, 175),
      appBar: AppBar(
        title: const Text(
          '享+社区',
          style: TextStyle(color: Colors.black),
        ),
        centerTitle: true,
        elevation: 0,
        backgroundColor: Colors.transparent,
      ),
      body: ListView(
        padding: const EdgeInsets.all(10),
        children: [
          ElevatedButton(
              onPressed: () {
                if (_count == 0) {
                  _count = 60;
                  _timer = Timer.periodic(const Duration(seconds: 1), (timer) {
                    setState(() {
                      if (_count > 0) {
                        _count--;
                      }
                    });
                  });
                }
              },
              child: const Text('开始')),
          Text('$_count秒'),
          ElevatedButton(
              onPressed: () {
                _timer?.cancel();
              },
              child: const Text('结束')),
          //导航栏
          HomeNav(),
          //图片
          ClipRRect(
            borderRadius: const BorderRadius.all(Radius.circular(10)),
            child: Image.asset('assets/images/banner@2x.jpg'),
          ),
          //公告
          HomeNotfiyList(notifyList: _notifyList),
        ],
      ),
    );
  }
}
